home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: help with strcmp
- Date: 2 Apr 1996 12:17:31 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4jr5sr$msn@sparcserver.lrz-muenchen.de>
- References: <4jpiek$lp6@blaze.cs.jhu.edu>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- lasher@hops.cs.jhu.edu (John E. Davis) writes:
-
- >For some reason when I try to compare the strings in the following
- >snippet I consistently get a core dump (running on a UNIX machine running
- >Solaris). Could anyone point out what may be going wrong? I have run it
- >through the debugger and that was no help at all for me. here is the
- >code snippet:
-
- >#include <stdio.h>
- >#include <stdlib.h>
- >#include <string.h>
-
- >void setup(FILE *);
-
- >void main(int argc, char *argv[])
-
- No comment!
-
- >{
- >char buf[20], data[40], *buff, *arg, *fp;
- >FILE *handle, *dest;
- >int n;
-
- >handle = fopen(argv[1], "r");
-
- You should not try to use "argv[1]" like that without making sure
- that argc is at least 2.
-
- >if(dest = fopen( "dbuild.out", "w")) setup(dest);
-
- You should not use a FILE * from fopen() without _first_ checking
- wether the fopen() call suceeded.
-
- >while(!feof(handle)) {
-
- feof() in C does not require the runtime system to make statements
- about the future. The "end of file" condition on a stream will be
- true _after_ trying to read beyond the end of the file, not before
- doing so. The FAQ for this newsgroup could have told you that.
-
- > n = 0;
- > fp = fgets(data, 40, handle);
-
- fgets() does return a pointer to the supplied buffer in case of
- success. It does return something different if the end of the FILE
- has been reached. The documentation that comes with your library
- could have told you that.
-
- > if ( strcasecmp(fp, "<action>\n") == 0) /* the coredump is here */
-
- Using a NULL pointer as a parameter to strcmp() - I will ignore the "
- case" for the moment - will lead to undesirable results on some
- systems. An operating system will issue a diagnostic message.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-